
/**
* @module session
* @author: Hjava
* @description: 会话定义类
* @since: 2018-07-23 11:36:01
*/
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
var sessionIdProcessor_1 = __webpack_require__(/*! _Eutils/sessionIdProcessor */ "./src/extra/utils/sessionIdProcessor.ts");
var constant_1 = __webpack_require__(/*! _util/constant */ "./src/core/utils/constant.ts");
var Session = /** @class */ (function () {
    function Session(_a) {
        var _b = _a.appId, appId = _b === void 0 ? 0 : _b, _c = _a.channelId, channelId = _c === void 0 ? 0 : _c, sid = _a.sid, _d = _a.uid, uid = _d === void 0 ? '0' : _d, _e = _a.type, type = _e === void 0 ? '' : _e, _f = _a.time, time = _f === void 0 ? 0 : _f, _g = _a.unreads, unreads = _g === void 0 ? 0 : _g, _h = _a.readTime, readTime = _h === void 0 ? 0 : _h, _j = _a.svrTime, svrTime = _j === void 0 ? 0 : _j, _k = _a.message, message = _k === void 0 ? null : _k, _l = _a._isCountUnread, _isCountUnread = _l === void 0 ? true : _l;
        this._isCountUnread = false;
        this.sessionId = '';
        this.appId = 0;
        this.channelId = 0;
        /*
        uid：
        1.单聊为:对方大象uid
        2.群聊为:群id
        3.公众号用户侧为:公众号id
        4.公众号客服侧为:公众号id_peeruid
        只有公众号客服侧peeruid才有值，表示聊天的对方的大象uid
        */
        this.uid = '0';
        this.type = ''; // 会话类型
        this.svrTime = 0; // 会话最后一条消息的服务端时间。通过svrTime和readTime可以知道会话是否有未读数
        this.time = 0; // 会话最后一条消息的客户端时间，此字段在业务逻辑上已经没有实际的作用，目前只有大象在使用用于排序会话列表，其他业务使用的是svrTime
        this.unreads = 0; // 会话的未读数
        this.readTime = 0; // 会话的服务端已读时间
        this.appId = appId;
        this.channelId = channelId;
        this.uid = uid;
        this.type = type;
        this.svrTime = svrTime;
        this.time = time;
        this.unreads = unreads;
        this.readTime = readTime;
        this.message = message;
        this.sid = sid;
        // 该字段用于表示当前会话的未读数是否计算完成,默认为 true.只有在判断本地会话和后端会话列表接口消息不一致时才设置为 false,计算成功后设置为 true
        this._isCountUnread = _isCountUnread;
        this.sessionId = sessionIdProcessor_1.default.create({ uid: this.uid, channelId: this.channelId, sid: this.sid });
    }
    Session.create = function (data) {
        switch (data.type) {
            case Session.TYPE.CHAT:
                return new ChatSession(data);
            case Session.TYPE.CHAT2:
                return new Chat2Session(data);
            case Session.TYPE.GROUP_CHAT:
                return new GroupChatSession(data);
            case Session.TYPE.PUB_CHAT:
                return new PubChatSession(data);
            case Session.TYPE.PUB_CHAT2:
                return new PubChat2Session(data);
            case Session.TYPE.CS_CHAT:
                return new CSChatSession(data);
            case Session.TYPE.CS_CHAT2:
                return new CSChatSession2(data);
            default:
                return null;
        }
    };
    Session.prototype.isChat = function () {
        return this.type === Session.TYPE.CHAT;
    };
    Session.prototype.isChat2 = function () {
        return this.type === Session.TYPE.CHAT2;
    };
    Session.prototype.isGroupChat = function () {
        return this.type === Session.TYPE.GROUP_CHAT;
    };
    Session.prototype.isPubChat = function () {
        return this.type === Session.TYPE.PUB_CHAT;
    };
    Session.prototype.isPubChat2 = function () {
        return this.type === Session.TYPE.PUB_CHAT2;
    };
    Session.prototype.isCSChat = function () {
        return this.type === Session.TYPE.CS_CHAT;
    };
    Session.prototype.isCSChat2 = function () {
        return this.type === Session.TYPE.CS_CHAT2;
    };
    Session.prototype.isCountUnread = function () {
        return this._isCountUnread;
    };
    Session.prototype.setCountUnreadFlag = function (value) {
        if (value === void 0) { value = true; }
        this._isCountUnread = value;
    };
    Session.prototype.toString = function () {
        return 'Session{'
            + ' _isCountUnread:' + this._isCountUnread
            + ' sessionId:' + this.sessionId
            + ' appId:' + this.appId
            + ' channelId:' + this.channelId
            + ' uid:' + this.uid
            + ' type:' + this.type
            + ' svrTime:' + this.svrTime
            + ' time:' + this.time
            + ' unreads:' + this.unreads
            + ' readTime:' + this.readTime
            + ' sid:' + this.sid
            + ' uuid:' + (this.message ? this.message.uuid : '')
            + ' mid:' + (this.message ? this.message.mid : '')
            + ' isCancel:' + (this.message ? this.message.isCancel : false)
            + ' }';
    };
    Session.TYPE = constant_1.SESSION_TYPE;
    return Session;
}());
exports.default = Session;
var ChatSession = /** @class */ (function (_super) {
    __extends(ChatSession, _super);
    function ChatSession(data) {
        return _super.call(this, data) || this;
    }
    return ChatSession;
}(Session));
var Chat2Session = /** @class */ (function (_super) {
    __extends(Chat2Session, _super);
    function Chat2Session(data) {
        return _super.call(this, data) || this;
    }
    return Chat2Session;
}(Session));
var GroupChatSession = /** @class */ (function (_super) {
    __extends(GroupChatSession, _super);
    function GroupChatSession(data) {
        return _super.call(this, data) || this;
    }
    return GroupChatSession;
}(Session));
var PubChatSession = /** @class */ (function (_super) {
    __extends(PubChatSession, _super);
    function PubChatSession(data) {
        var _this = _super.call(this, data) || this;
        _this.pubId = '';
        _this.pubId = data.uid || '';
        return _this;
    }
    return PubChatSession;
}(Session));
var PubChat2Session = /** @class */ (function (_super) {
    __extends(PubChat2Session, _super);
    function PubChat2Session(data) {
        var _this = _super.call(this, data) || this;
        _this.pubId = '';
        _this.pubId = data.uid || '';
        return _this;
    }
    return PubChat2Session;
}(Session));
var CSChatSession = /** @class */ (function (_super) {
    __extends(CSChatSession, _super);
    function CSChatSession(data) {
        var _this = _super.call(this, data) || this;
        _this.pubId = '';
        _this.peerUid = '';
        _this.pubId = data.pubId || '';
        _this.peerUid = data.peerUid || '';
        return _this;
    }
    return CSChatSession;
}(Session));
var CSChatSession2 = /** @class */ (function (_super) {
    __extends(CSChatSession2, _super);
    function CSChatSession2(data) {
        var _this = _super.call(this, data) || this;
        _this.pubId = '';
        _this.peerUid = '';
        _this.pubId = data.pubId || '';
        _this.peerUid = data.peerUid || '';
        return _this;
    }
    return CSChatSession2;
}(Session));


//# sourceURL=webpack://MTDX/./src/extra/models/session.ts?